package com.sardine.base.design;

import com.alibaba.fastjson.JSON;
import com.sardine.base.design.api.ListenerHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 上海京东到家元信信息技术有限公司<br>
 * Created with IntelliJ IDEA.
 * Date:2017/10/9
 * Time:15:52
 * 监听者触发器
 * @author daifeng<br>
 *         daifeng@imdada.cn
 * @since JDK 1.7 <br>
 * Copyright (c) 2017 imdada System Incorporated All Rights Reserved.
 */
public class CommandTrigger {
    private static final Logger logger = LoggerFactory.getLogger(CommandTrigger.class);

    public void activate(List<ListenerHandler> commend,RobotEvent event) {
        if(!CollectionUtils.isEmpty(commend)){
            for (ListenerHandler listenerHandler : commend) {
                try {
                    listenerHandler.execute(event);
                } catch (Exception e) {
                    logger.error("监听器执行异常，入参："+ JSON.toJSON(event),e);
                }
            }
        }
    }
}
